{	Problem: http://codeforces.ru/problemset/problem/5/A
	Verdict: Accepted

}
var n:longint; r:int64; s:String;
begin
r:=0;
n:=0;
readln(s);
while s<>'' do begin
    if s[1]='+' then inc(n) else
    if s[1]='-' then dec(n) else begin
        delete(s,1,pos(':',s));
        inc(r,length(s)*n);  
    end;
    readln(s);
end;
writeln(r);
end.